package com.lanou3g.code0417.dirty;

/**
 * Created by dllo on 18/4/17.
 */
public class Main {
    public static void main(String[] args) {

        // 匿名内部类中要使用外部定义的局部变量，该局部变量需要是final 类型
        final Utils utils = new Utils();
        final Person person = new Person("zs",12);

        new Thread(){
            @Override
            public void run() {
                utils.updatePerson(person,"李四",19);
            }
        }.start();

        System.out.println(person.getName()+ "   "+person.getAge());
        //为了演示脏读，让线程停止500ms，保证修改了用户名，还没来得及修改年龄呢
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();

        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                utils.showPerson(person);
            }
        }).start();
        System.out.println("***********" + person.getName()+ "   "+person.getAge());

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        new Thread(new Runnable() {
            @Override
            public void run() {
                utils.showPerson(person);
            }
        }).start();


    }

}
